//
//  ShowView.m
//  EquiriesProject
//
//  Created by qianfeng on 15/10/29.
//  Copyright (c) 2015年 HXH. All rights reserved.
//

#import "ShowView.h"
#import "AddDriveVC.h"

extern int _myitem;

@implementation ShowView
{
    UIView * bgGroundView;
    UIView * showView;
    UITableView * _tableView;
}

-(id)initWithFrame:(CGRect)rect
{
    self = [super initWithFrame:rect];
    if (self) {
        //在这里创建，提示View
        //获取window，只有一个window
        NSArray * array = @[@"小型车",@"大型车"];
        UIWindow * window = [[UIApplication sharedApplication] keyWindow];
        bgGroundView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        bgGroundView.backgroundColor = [UIColor clearColor];
        //bgGroundView.alpha = 0.5;
        UITapGestureRecognizer * tap0 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
        tap0.numberOfTapsRequired = 1;
        //添加一个手势到某个视图上
        [bgGroundView addGestureRecognizer:tap0];
        [window addSubview:bgGroundView];
        bgGroundView.hidden = YES;
        
        showView = [[UIView alloc] initWithFrame:rect];
        showView.backgroundColor = [UIColor clearColor];
        showView.userInteractionEnabled = YES;
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
        tap.numberOfTapsRequired = 1;
        //添加一个手势到某个视图上
        [showView addGestureRecognizer:tap];
        [window addSubview:showView];
        
        showView.hidden = YES;
        
        if (_myitem == 0) {
            for (int i=0; i<2; i++) {
                UIButton * button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0+(rect.size.height/2)*i, rect.size.width, rect.size.height/2)];
                button.backgroundColor = [UIColor whiteColor];
                [button setTitle:array[i] forState:UIControlStateNormal];
                [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                button.tag = 100+i;
                button.layer.borderWidth = 1;
                button.layer.borderColor = [UIColor grayColor].CGColor;
                [showView addSubview:button];
                [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
            }
        }
        
    }
    return self;
}


-(void)tap
{
    if ([self.delegate respondsToSelector:@selector(viewDisappear:)]) {
        [self.delegate viewDisappear:nil];
    }
}

-(void)buttonClick:(UIButton*)button
{
    if ([self.delegate respondsToSelector:@selector(viewDisappear:)]) {
        [self.delegate viewDisappear:button.currentTitle];
    }
}

//-(void)showButtonClick
//{
//    if ([self.delegate respondsToSelector:@selector(viewDisappear:)]) {
//        [self.delegate viewDisappear:nil];
//    }
//}

-(void)disappearView
{
    bgGroundView.hidden = YES;
    showView.hidden = YES;
}

-(void)looklookView
{
    bgGroundView.hidden = NO;
    showView.hidden = NO;
}



@end
